package com.sunducation.wts.penbox.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.sunducation.wts.penbox.R;
import com.wetao.lib_common.bean.response.ExamListInfo;

import java.util.List;

/**
 * author: zhouyh
 * created on: 3/9/21 3:52 PM
 * description: 作业记录适配器
 */
public class WorkRecordAdapter extends RecyclerView.Adapter<WorkRecordAdapter.RecordViewHolder> {



    private Context mContext;
    private List<ExamListInfo.DataBean.RecordsBean> recordsBeans;



    public WorkRecordAdapter(Context mContext, List<ExamListInfo.DataBean.RecordsBean> noticeBeans) {
        this.mContext = mContext;
        this.recordsBeans = noticeBeans;
    }

    @NonNull
    @Override
    public RecordViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View root = LayoutInflater.from(mContext).inflate(R.layout.work_record_item,viewGroup,false);
        return new RecordViewHolder(root);
    }

    @Override
    public void onBindViewHolder(@NonNull RecordViewHolder recordViewHolder, int i) {



        recordViewHolder.tvTitle.setText(recordsBeans.get(i).getExamName());
        recordViewHolder.tvTime.setText(recordsBeans.get(i).getFinishTime());
        recordViewHolder.tvNumber.setText(recordsBeans.get(i).getAnswerAmount() + "/" + recordsBeans.get(i).getTotalQuestion());


        recordViewHolder.rlWorkItem.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                recordViewHolder.tvTitle.setTextColor(mContext.getResources().getColor(R.color.wifi_Text6));
                if (hasFocus){
                    recordViewHolder.tvTitle.setTextColor(mContext.getResources().getColor(R.color.wifi_line));
                }
            }
        });

        recordViewHolder.rlWorkItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (recordItemClickListener!=null){
                    recordItemClickListener.OnItemClickListener(i);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return recordsBeans.size();
    }

    class RecordViewHolder extends RecyclerView.ViewHolder{

        private RelativeLayout rlWorkItem;
        private TextView tvTitle;
        private TextView tvNumber;
        private TextView tvTime;

        public RecordViewHolder(@NonNull View itemView) {
            super(itemView);
            rlWorkItem = itemView.findViewById(R.id.rl_record_item);
            tvTitle = itemView.findViewById(R.id.tv_work_title);
            tvTime = itemView.findViewById(R.id.tv_work_time);
            tvNumber = itemView.findViewById(R.id.tv_work_number);
        }
    }


    private OnRecordItemClickListener recordItemClickListener;
    public interface OnRecordItemClickListener{
        void OnItemClickListener(int position);
    }

    public void setRecordItemClickListener(OnRecordItemClickListener workItemClickListener) {
        this.recordItemClickListener = workItemClickListener;
    }
}
